//
//  DesView.m
//  HappyTrip
//
//  Created by GeminyXC on 15-4-4.
//  Copyright (c) 2015年 lanou3g.com 蓝鸥科技. All rights reserved.
//

#import "DesView.h"
#import "DesCollectTVC.h"
#import "DesDataObj.h"
#import "DestinationPlaceViewController.h"

#define COLLECTIONIdentifier @"collectionViewCellReuse"

@implementation DesView

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

- (void)dealloc
{
//    [_detailObject release];
    [_tableView release];
    [_desArr release];
    [super dealloc];
}

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = [UIColor yellowColor];
        
        self.tableView = [[UITableView alloc] initWithFrame:self.bounds style:UITableViewStylePlain];
        self.tableView.backgroundColor = [UIColor colorFromHexCode:@"#F5FFFA"];
        self.tableView.dataSource = self;
        self.tableView.delegate = self;
        [self addSubview:_tableView];
        [_tableView release];
        
        //---- 注册重用池
        [self.tableView  registerClass:[UITableViewCell class] forCellReuseIdentifier:COLLECTIONIdentifier];
    }
    return self;
}

- (void)layoutSubviews
{
    [super layoutSubviews];
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if (0 == self.desArr.count) {
        [self.tableView setSeparatorStyle:UITableViewCellSeparatorStyleNone];
        self.tableView.backgroundView = [[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"collect.png"]] autorelease];
    }else
    {
        self.tableView.backgroundView = nil;
        [self.tableView setSeparatorStyle:UITableViewCellSeparatorStyleSingleLine];
    }
    self.desArr = [NSMutableArray array];
    self.desArr = [[DesDataObj shareInstance] selectAllSpots];
    return self.desArr.count;

}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:COLLECTIONIdentifier];
    cell.layer.cornerRadius = 10;
    cell.clipsToBounds = YES;
    cell.backgroundColor = [UIColor colorFromHexCode:@"#F5FFFA"];
    cell.textLabel.text = [[self.desArr objectAtIndex:indexPath.row] name];
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{

    DestinationPlaceViewController *placeVC = [[DestinationPlaceViewController alloc] init];
    placeVC.placeSendID = [[self.desArr objectAtIndex:indexPath.row] idNumber];
    placeVC.placeSendType = [[self.desArr objectAtIndex:indexPath.row] typeNumber];
    [self.target pushViewController:placeVC animated:YES];
    [placeVC release];

}


@end
